$('#loginBtn').click(function () {
    var email = $.trim($("#email").val());
    var password = $.trim($("#password").val());
    var loginTips = $('#loginTips');
    var valicode = $('#valicode').val();
    if(email == null || email == '') {
        loginTips.show();
        loginTips.text('请输入您登录邮箱！');
        return false;
    }
    if(!isEmail(email)) {
        loginTips.show();
        loginTips.text('您输入的邮箱格式错误！');
        return false;
    }
    if(password == null || password == '' || password.length < 6) {
        loginTips.show();
        loginTips.text('请输入正确的密码！');
        return false;
    }
    if(password.length < 6) {
        loginTips.show();
        loginTips.text('密码长度不正确！');
        return false;
    }
    if(valicode == null || valicode == '') {
        loginTips.show();
        loginTips.text('请输入验证码！');
        return false;
    }
    loginTips.text('');
    loginTips.hide();

    var param = {email:email,password:password,valicode:valicode}

    var retUrl = $('#retUrl').val();
    if(retUrl == null || retUrl == ''|| retUrl.indexOf('toRegister') > 0) {
        retUrl = '/';
    }
    $.ajax({
        url:"loginSubmit",
        type:"post",
        data:param,
        success:function(data){

            if(data.code == 0) {
                window.location.href = retUrl;
            }else {
                loginTips.show();
                loginTips.text(data.msg);
                changeCode();
            }
        }
    });
})

$('#codeImage').click(function () {
    changeCode();
})

function changeCode() {
    $('#codeImage').attr('src','/validateCode/authCode?abc='+Math.random());//链接后添加Math.random，确保每次产生新的验证码，避免缓存问题。
}